using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace SaleManagement.Entity.Mapping
{
    public class ProductDetailMap : EntityTypeConfiguration<ProductDetail>
    {
        public ProductDetailMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Name)
                .IsRequired()
                .HasMaxLength(100);

            this.Property(t => t.Summary)
                .IsRequired()
                .HasMaxLength(200);

            this.Property(t => t.Detail)
                .IsRequired();

            // Table & Column Mappings
            this.ToTable("ProductDetail");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.ProductId).HasColumnName("ProductId");
            this.Property(t => t.LanguageId).HasColumnName("LanguageId");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.Summary).HasColumnName("Summary");
            this.Property(t => t.Detail).HasColumnName("Detail");
            this.Property(t => t.UnitPrice).HasColumnName("UnitPrice");

            // Relationships
            this.HasOptional(t => t.Language)
                .WithMany(t => t.ProductDetails)
                .HasForeignKey(d => d.LanguageId);
            this.HasRequired(t => t.Product)
                .WithMany(t => t.ProductDetails)
                .HasForeignKey(d => d.ProductId);

        }
    }
}
